package com.example.meiyu.application;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    MyApp myApp;
    private EditText edt;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myApp = (MyApp)getApplication();
        edt=(EditText)findViewById(R.id.editText);
        btn= (Button) findViewById(R.id.button);

        String app=myApp.getLabel();
        if(app.equals("")||app==null)
        {
            btn.setOnClickListener(new MyButton());
        }
        else{
            Intent intent=new Intent();
            intent.setClass(MainActivity.this,SecondActivity.class);
            finish();
            startActivity(intent);
        }
    }
    private class MyButton implements View.OnClickListener {

        public void onClick(View v){
            String text=edt.getText().toString().trim();
            myApp.setLabel(text);
            Intent intent=new Intent();
            intent.setClass(MainActivity.this,SecondActivity.class);
            finish();
            startActivity(intent);
        }
    }
}
